package cn.iocoder.yudao.module.knowledge.dal.mysql.tree;

import java.util.*;

import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.knowledge.dal.dataobject.tree.KnowledgeTreeDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.knowledge.controller.admin.tree.vo.*;

/**
 * 知识库结构树 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface KnowledgeTreeMapper extends BaseMapperX<KnowledgeTreeDO> {

    default List<KnowledgeTreeDO> selectList(KnowledgeTreeListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<KnowledgeTreeDO>()
                .betweenIfPresent(KnowledgeTreeDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(KnowledgeTreeDO::getParentId, reqVO.getParentId())
                .likeIfPresent(KnowledgeTreeDO::getNodeName, reqVO.getNodeName())
                .orderByAsc(KnowledgeTreeDO::getOrderIndex)
                .orderByDesc(KnowledgeTreeDO::getId));
    }

    default KnowledgeTreeDO selectByParentIdAndNodeName(Long parentId, String nodeName) {
        return selectOne(KnowledgeTreeDO::getParentId, parentId, KnowledgeTreeDO::getNodeName, nodeName);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(KnowledgeTreeDO::getParentId, parentId);
    }

}